//
//  NSAttributString+Extension.swift
//  CLWeibo
//
//  Created by 陈亮 on 16/7/22.
//  Copyright © 2016年 陈亮. All rights reserved.
//

import UIKit

extension NSAttributedString {
    class func attribuedStringWithEmoicon (emoicon:CLEmoiconModel,font:UIFont) -> NSAttributedString {
        //获取点击图片
        let image = UIImage(named: emoicon.path!)
        //生成一个文本附件
        let attachment = CLTextAttachment()
        attachment.image = image
        //设置模型
        attachment.emoicon = emoicon
        //获取字体高度
        let fontHeight = font.lineHeight
        //图片和文字没有对齐  修改bounds
        attachment.bounds = CGRect(x: 0, y: -4, width: fontHeight, height: fontHeight)
        //根据文本附件 生成富文本
        let attributedStr = NSAttributedString(attachment: attachment)
        return attributedStr
    }
}